package edu.tyut.game.ui.person

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.switchMap
import edu.tyut.game.logic.FlyingFlowerOrderRepository
import edu.tyut.game.logic.UserRepository
import okhttp3.MultipartBody

class PersonViewModel : ViewModel() {

    private val headIconUpdateLiveDate = MutableLiveData<List<MultipartBody.Part>>()
    val resHeadIconUpdate = headIconUpdateLiveDate.switchMap {
        UserRepository.updateHeadIcon(it)
    }
    fun headIconUpdate(files: List<MultipartBody.Part>){
        headIconUpdateLiveDate.value = files
    }

    // 获取胜率排行
    private val winRateRankLiveData = MutableLiveData<Int>()
    val resWinRateRank = winRateRankLiveData.switchMap {
        FlyingFlowerOrderRepository.getWinRateRank()
    }
    fun getWinRateRank(num: Int){
        winRateRankLiveData.value = num
    }
    // 获取总局数排行
    private val totalRoundsRankLiveData = MutableLiveData<Int>()
    val resTotalRoundsRank = winRateRankLiveData.switchMap {
        FlyingFlowerOrderRepository.getTotalRoundsRank()
    }
    fun getTotalRoundsRank(num: Int){
        totalRoundsRankLiveData.value = num
    }

    private val winRateTotalRoundsRankLiveData = MutableLiveData<Int>()
    val resWinRateTotalRoundsRank = winRateRankLiveData.switchMap {
        FlyingFlowerOrderRepository.getWinRateRankTotalRoundsRank()
    }
    fun getWinRateRankTotalRoundsRank(){
        winRateTotalRoundsRankLiveData.value = winRateTotalRoundsRankLiveData.value
    }
}